package com.allwees.bs.core.model.wf.entity;

import com.allwees.bs.core.modelbase.entity.BaseEntity;
import com.allwees.core.wf.Action;
import com.allwees.core.wf.FsmState;
import com.allwees.core.wf.Workflow;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.MappedSuperclass;

/**
 * 工作流实体基类
 *
 * @param <S>
 * @param <A>
 * @author yangylsky
 * @since 2019-12-10
 */
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@MappedSuperclass
public abstract class WorkflowEntity<S extends FsmState<S, A>, A extends Action> extends BaseEntity implements Workflow<S, A> {
    /**
     * 上一个操作
     */
    @Column(columnDefinition = "varchar(255)")
    @Enumerated(EnumType.STRING)
    protected A latestAction;

    /**
     * 上一个状态
     */
    @Column(columnDefinition = "varchar(255)")
    @Enumerated(EnumType.STRING)
    protected S backState;

    /**
     * 当前状态
     */
    @Column(columnDefinition = "varchar(255)")
    @Enumerated(EnumType.STRING)
    protected S state;

    @Override
    public String getBsKey() {
        return getUuid();
    }
}
